/*
   BaseService.h
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 27 December 2006
*/

#ifndef _BOOYO_POS_BASESERVICE_H_
#define _BOOYO_POS_BASESERVICE_H_

#include "EventCallbacks.h"

#include <BooyoPOSException.h>
#include <const/BooyoPOSConst.h>

namespace booyopos
{

namespace services
{

class CBaseService : public CBooyoPOSConst, public events::CBooyoPOSEvents
{
public:
	bool			autoDisable;
	int				state;
	std::string		checkHealthText;
	bool			claimed;
	bool			dataEventEnabled;
	bool 			deviceEnabled;
	bool			freezeEvents;
	int				outputID;

	std::string		deviceServiceDescription;
	int				deviceServiceVersion;
	std::string		physicalDeviceDescription;
	std::string		physicalDeviceName;


	int				fd;
	bool			bOpen;

	/* Access Serial Port */
	struct termios oldtermio, newtermio;

public:
	CBaseService();
	~CBaseService();

	/* Properties */
	std::string GetCheckHealthText() throw (CByException);
	bool GetClaimed() throw (CByException);
	bool GetDeviceEnabled() throw (CByException);
	void SetDeviceEnabled(bool deviceEnabled) throw (CByException);
	std::string GetDeviceServiceDescription() throw (CByException);
	int GetDeviceServiceVersion() throw (CByException);
	bool GetFreezeEvents() throw (CByException);
	void SetFreezeEvents(bool freezeEvents) throw (CByException);
	std::string GetPhysicalDeviceDescription() throw (CByException);
	std::string GetPhysicalDeviceName() throw (CByException);
	int GetState();

	/* Methods */
	int Open(std::string logicalDeviceName, EventCallbacks cb) throw (CByException); // Opens a device for subsequent I/O
	void Close() throw (CByException);					// Releases the device and its resources
	void Claim(int timeout) throw (CByException); 		// Requests exclusive access to the device
	void Release() throw (CByException);					// Releases exclusive access to the device
	void CheckHealth(int level) throw (CByException); 	// Tests the state of a device
	void DirectIO(int command, int data, void* obj) throw (CByException); // Communicates directly with the UnifiedPOS Service
};

} // namespace services

} // namespace booyopos

#endif // _BOOYO_POS_BASESERVICE_H_
